package com.zhaotianhao.rentingservice.api;

import com.zhaotianhao.rentingservice.common.JsonResult;
import com.zhaotianhao.rentingservice.entity.Log;
import com.zhaotianhao.rentingservice.entity.Type;
import com.zhaotianhao.rentingservice.mapper.LogRepository;
import com.zhaotianhao.rentingservice.service.ILogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author Z-7
 * @Date 2022/5/16
 */
@Slf4j
@Component
public class TypeApiFallback implements TypeApi{
    @Autowired
    private ILogService iLogService;

    @Autowired
    private LogRepository logRepository;

    @Override
    public JsonResult getAllType() {
        log.error("租房服务调用基础服务接口，获取房源类型出现异常");
        Log log = new Log();
        log.setId(UUID.randomUUID().toString()).setOperation("获取房源类型").setOperationTime(new Date());
        iLogService.save(log);
        logRepository.save(log);
        return JsonResult.faild("租房服务调用基础服务接口，获取房源类型出现异常");
    }

    @Override
    public Type getById(Integer id) {
        log.error("租房服务调用基础服务接口，根据id获取房源类型");
        Log log = new Log();
        log.setId(UUID.randomUUID().toString()).setOperation("根据id获取房源类型，熔断").setOperationTime(new Date());
        iLogService.save(log);
        logRepository.save(log);
        return null;
    }
}
